package cn.tannn.tcache.command.string;

import cn.tannn.tcache.core.Command;
import cn.tannn.tcache.core.Reply;
import cn.tannn.tcache.core.Tcache;

/**
 * set 命令 [设置key value]
 * <p> set k1 v1
 *
 * @author <a href="https://t.tannn.cn/">tnnn</a>
 * @version V1.0
 * @date 2024/6/19 下午9:08
 */
public class SetCommand implements Command {
    @Override
    public String name() {
        return "SET";
    }

    @Override
    public Reply<?> exec(Tcache cache, String[] args) {
        if (args.length == 7) {
            cache.set(args[4], args[6]);
            return Reply.string(OK);
        } else if (args.length == 6) {
            cache.set(args[4], "");
            return Reply.string(OK);
        } else {
            return Reply.error("value not allow empty");
        }
    }
}
